package com.liury.bbs.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liury.bbs.entity.Reply;
import com.liury.bbs.entity.Title;
import com.liury.bbs.entity.User;
import com.liury.bbs.mapper.ReplyMapper;
import com.liury.bbs.mapper.TitleMapper;
import com.liury.bbs.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    TitleMapper titleMapper;
    @Autowired
    ReplyMapper replyMapper;

    public PageInfo<User> findAllUsers(Integer pageNo, Integer pageSize, String key){
        if("null".equals(key)) key="";
        PageHelper.startPage(pageNo,pageSize);
        List<User> userList=userMapper.getUsers(key);
        PageInfo<User> userPageInfo=new PageInfo<>(userList);
        return userPageInfo;
    }

    //主题
    public PageInfo<Title> getALlTitles(Title t,Integer pageNo,Integer pageSize){
        PageHelper.startPage(pageNo,pageSize);
        List<Title> titleList=titleMapper.getAllTitles(t);
        PageInfo<Title> titlePageInfo=new PageInfo<>(titleList);
        return titlePageInfo;
    }
    //帖子
    public PageInfo<Reply> getAllReplies(Reply reply,Integer pageNo,Integer pageSize){
        PageHelper.startPage(pageNo,pageSize);
        List<Reply> replyList=replyMapper.getReplies(reply);
        PageInfo<Reply> replyPageInfo=new PageInfo<>(replyList);
        return replyPageInfo;
    }
}
